<?php




$ch = curl_init(); 
$data = "&uscLogon%24User=nkarsenty%40orinea.com&uscLogon%24password=Ernst1603&uscLogon%24chkRememberMe=on&uscLogon%24btnSubmit=Sign+In&target_p=-SM-HTTPS%3A%2F%2Femeadmz02.ey.com%2Fmarketing%2Ffralumni.nsf%2F0%2F835449905012EF5AC12579AE005BD8B9%3FEdit%26Lang%3DFR&user=nkarsenty%40orinea.com&smagentname=&smauthreason=0&postpreservationdata=&SMReason=&language=&entity=0&SMENC=ISO-8859-1&SMLOCALE=EN&";
$url = "https://eyonline.ey.com/eysso/unprotected/logon.aspx?TYPE=33554433&REALMOID=06-97864146-e2a6-46d1-9ed7-060ce2004772&GUID=&SMAUTHREASON=0&METHOD=GET&SMAGENTNAME=yhWQlaxcAHs4x7rJ7XNeMmiA3YqdbfJ6pTFHP6nr6zEUNdvLvWoD5pRMFKL4E6Bj&TARGET=-SM-HTTPS%3a%2f%2femeadmz02.ey.com%2fmarketing%2ffralumni.nsf%2f0%2f835449905012EF5AC12579AE005BD8B9%3fEdit%26Lang%3dFR";
$cookie_file_path = "tmp/";		
//$url = 'https://eyonline.ey.com/eysso/unprotected/logon.aspx';
$agent = "Mozilla/4.0 (compatible;MSIE 5.01; Windows -NT 5.0)";

curl_setopt($ch, CURLOPT_URL, $url.$data); 
curl_setopt($ch, CURLOPT_USERAGENT, $agent); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS,$data); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
//curl_setopt($ch, CURLOPT_REFERER, $reffer);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); 
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$result = curl_exec($ch); 
var_dump($result);

$url2 = "https://emeadmz02.ey.com/marketing/fralumni.nsf/0/835449905012EF5AC12579AE005BD8B9?Edit&Lang=FR"; //Wishing I could use $_GET here, in order to retrieve the session ID from the first result page


$POSTFIELDS2 = 'field=value&anotherfield=value2';

curl_setopt($ch, CURLOPT_URL, $url2);
//curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); 
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); 
$result2 = curl_exec($ch); 
var_dump($result2);
curl_close($ch);





/*
// INIT CURL
$ch = curl_init();

// SET URL FOR THE POST FORM LOGIN
//curl_setopt($ch, CURLOPT_URL, 'https://eyonline.ey.com/eysso/unprotected/logon.aspx');
curl_setopt($ch, CURLOPT_URL, 'https://emeadmz02.ey.com/marketing/fralumni.nsf/0/835449905012EF5AC12579AE005BD8B9?Edit&Lang=FR');

// ENABLE HTTP POST
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
$data = "uscLogon%24User=nkarsenty%40orinea%2Ecom&uscLogon%24btnSubmit=Sign%20In&uscLogon%24password=Ernst1603";
$data .= "&target_p=-SM-HTTPS%3A%2F%2Femeadmz02.ey.com%2Fmarketing%2Ffralumni.nsf%2F0%2F835449905012EF5AC12579AE005BD8B9%3FEdit%26Lang%3DFR";


// IMITATE CLASSIC BROWSER'S BEHAVIOUR : HANDLE COOKIES
//curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');

# Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
# not to print out the results of its query.
# Instead, it will return the results as a string return value
# from curl_exec() instead of the usual true/false.
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

// EXECUTE 1st REQUEST (FORM LOGIN)
if( !$store = curl_exec($ch)) 
{ 
  echo trigger_error(curl_error($ch)); 
}

$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($code == 301 || $code == 302 ) 
{ 
	var_dump($store);
	preg_match('/Location:(.*?)\n/', $store, $matches); 
	$newurl = trim(array_pop($matches)); 
	var_dump($newurl);
} 
else 
{ 
	$code = 0; 
}


exit;


curl_setopt ($ch, CURLOPT_POST, 1);						
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
echo curl_error($ch);
//echo $store;
var_dump("Passed Login Page");
// SET FILE TO DOWNLOAD
curl_setopt($ch, CURLOPT_URL, 'https://emeadmz02.ey.com/marketing/fralumni.nsf/0/835449905012EF5AC12579AE005BD8B9?Edit&Lang=FR');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POST, 1);

// EXECUTE 2nd REQUEST (FILE DOWNLOAD)
if(!$result = curl_exec($ch)) 
{ 
   trigger_error(curl_error($ch)); 
}
echo curl_error($ch);
var_dump($result);
// CLOSE CURL
curl_close ($ch); 

?>
*/